﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Refl.Dreaming
{
    public class DreamInfo
    {
        public DreamInfo(DreamType t)
        {
            _RequireNameUpdate = true;
            this.DreamType = t;
            switch (t)
            {
                case DreamType.Dream:
                    this.Debug = Global.IsDebug;
                    this.DreamType = DreamType.Dream;
                    this.AssemblyReferences = DreamInfo.DefaultReferencesFor(t);
                    this.Threaded = false;
                    break;
                case DreamType.Reverie:
                    this.Debug = Global.IsDebug;
                    this.DreamType = DreamType.Reverie;
                    this.AssemblyReferences = DreamInfo.DefaultReferencesFor(DreamType.Reverie);
                    this.Threaded = true;
                    break;
            }
        }

        #region 'Properties'

        private DreamLanguage _Language;
        public DreamLanguage Language
        {
            get { return _Language; }
            set { _Language = value; _RequireNameUpdate = true; }
        }
        //is the dream in debug mode?
        private bool _Debug;
        public bool Debug
        {
            get { return _Debug; }
            set { _Debug = value; _RequireNameUpdate = true; }
        }
        //should the dream run in its own thread?
        private bool _Threaded;
        public bool Threaded
        {
            get { return _Threaded; }
            set { _Threaded = value; _RequireNameUpdate = true; }
        }
        private List<string> _Refs;
        public List<string> AssemblyReferences
        {
            get { return _Refs; }
            set { _Refs = value; _RequireNameUpdate = true; }
        }
        //this is very important, and will be indispesable when method=>dream gets implemented.
        internal DreamType DreamType;
        //
        internal string _Name = "";
        /// <summary>
        /// The Dream Name. This is the unique Dream identifier.
        /// </summary>
        public string Name { get { return _Name; } }
        //
        internal bool _RequireNameUpdate;
        #endregion

        // Static methods -----------------------------------
        internal static List<string> DefaultReferencesFor(DreamType T)
        {
            if (T == DreamType.Dream)
            {
                List<string> result = new List<string>();
                result.Add("mscorlib.dll");
                result.Add("System.dll");
                result.Add("System.Core.dll");
                result.Add("System.Xml.dll");
                result.Add("System.Xml.Linq.dll");
                return result;
            }
            if (T == DreamType.Reverie)
            {
                List<string> result = new List<string>();
                result.Add("mscorlib.dll");
                result.Add("System.dll");
                result.Add("System.Core.dll");
                result.Add("System.Data.dll");
                result.Add("System.Xml.dll");
                result.Add("System.Xml.Linq.dll");
                result.Add("System.Data.DataSetExtensions.dll");
                result.Add("System.Windows.Forms.dll");
                result.Add("System.Drawing.dll");
                result.Add("System.Deployment.dll");
                return result;
            }
            return new List<string>();
        }
        internal static List<string> DefaultNamespacesFor(DreamType T)
        {
            if (T == DreamType.Dream)
            {
                List<string> result = new List<string>();
                result.Add("System");
                result.Add("System.Collections.Generic");
                result.Add("System.Linq");
                result.Add("System.Text");
                result.Add("System.IO");
                return result;
            }
            if (T == DreamType.Reverie)
            {
                List<string> result = new List<string>();
                result.Add("System");
                result.Add("System.Collections.Generic");
                result.Add("System.Linq");
                result.Add("System.Text");
                result.Add("System.IO");
                result.Add("System.ComponentModel");
                result.Add("System.Drawing");
                result.Add("System.Windows.Forms");
                result.Add("System.Text.RegularExpressions");
                result.Add("System.Diagnostics");
                result.Add("System.Linq.Expressions");
                result.Add("System.Threading");
                result.Add("System.Reflection");
                return result;
            }
            return new List<string>();
        }
    }

    public class ScriptInfo
    {
        public ScriptInfo()
        {
            this._RequireNameUpdate = true;
            this.Threaded = false;
        }
        #region 'Properties'

        private ScriptLanguage _Language;
        public ScriptLanguage Language
        {
            get { return _Language; }
            set { _Language = value; _RequireNameUpdate = true; }
        }
        //should the script run in its own thread?
        private bool _Threaded;
        public bool Threaded
        {
            get { return _Threaded; }
            set { _Threaded = value; _RequireNameUpdate = true; }
        }
        internal string _Name = "";
        /// <summary>
        /// The Dream Name. This is the unique Dream identifier.
        /// </summary>
        public string Name { get { return _Name; } }
        //
        internal bool _RequireNameUpdate;
        #endregion
    }
    public enum DreamType
    {
        Unknown = 0,
        Dream = 1,
        Script = 2,
        Reverie = 3,
    }
}